package cn.tedu.egmvc1.controller;

import cn.tedu.egmvc1.pojo.dto.AddDTO;
import cn.tedu.egmvc1.pojo.entity.Employee;
import org.apache.ibatis.annotations.Delete;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;

@Controller
public class EmpController {
/**
 * 1）添加员工[DTO类接收数据]
 * 请求地址：/emp/insert
 * 请求方法：GET
 * 查询参数：员工姓名name、员工工资salary、员工岗位job
 * 返回响应：String "添加成功"
 */
    @RequestMapping("/emp/insert")
    @ResponseBody
    public String insertEmployee(String name,Double salary,String job){
        AddDTO addDTO = new AddDTO();
        addDTO.setName(name);
        addDTO.setSalary(salary);
        addDTO.setJob(job);

        return addDTO.getName()+":"+addDTO.getSalary()+":"+addDTO.getJob()+"  添加成功";
    }

/**
 * 2）查询所有员工的信息
 * 请求地址：/emp/select
 * 请求方法：GET
 * 查询参数：无
 * 返回响应：String "恭喜,查询成功"
 */

    @RequestMapping("/emp/select")
    @ResponseBody
    public String selectEmployee(Employee employee){
        Integer id = employee.getId();
        String name = employee.getName();
        Double salary = employee.getSalary();
        String job = employee.getJob();

        return id + ":" + name + ":" + salary + ":" + job + "  恭喜,查询成功";
    }

/**
 * ）修改员工信息[实体类接收数据]
 * 请求地址：/emp/update
 * 请求方法：GET
 * 查询参数：id=员工编号&name=员工姓名&salary=员工工资&job=员工岗位
 * 返回响应：String "修改成功"
 */

    @RequestMapping("/emp/update")
    @ResponseBody
    public String updateEmp(Integer id,String name,Double salary,String job){
        Employee employee = new Employee();
        employee.setId(id);
        employee.setName(name);
        employee.setSalary(salary);
        employee.setJob(job);

        return employee+"修改成功";
    }

/**
 * 4）删除员工信息[声明参数方式接收]
 * 请求地址：/emp/delete
 * 请求方法：GET
 * 查询参数：id=员工编号
 * 返回响应：字符串 "删除成功"
 */

    @RequestMapping("/emp/delete")
    @ResponseBody
    public String deleteEmp(Integer id){
        Employee employee = new Employee();
           employee.setId(id);
           employee.setJob(null);
           employee.setName(null);
           employee.setSalary(null);

           return employee.toString()+" 删除成功";
        }

    }



